//父类
// class People {
//     constructor(name, age){
//         this.name = name;
//         this.age = age;
//     }
//     eat(){
//         alert(`${this.name} eat something`);
//     }
//     speak(){
//         alert(`My name is ${this.name}, age ${this.age}`)
//     }
// }

// //子类
// class Student extends People {
//     constructor(name, age, number){
//         super(name, age);
//         this.number = number;
//     }
//     study() {
//         alert(`${this.name} study`)
//     }
// }

// let xiaoming = new Student('小明', 10, 'A1');
// xiaoming.study();
// alert(xiaoming.number)
// xiaoming.eat();

// let xiaohong = new Student('小红', 11, 'A2');
// xiaohong.study()
// xiaohong.speak()

{
    function loadImg(src) {
        let promise = new Promise(function(resolve, reject) {
            let img = document.createElement('img');
            img.onload = function(){
                resolve(img);
            }
            img.onerror=function(){
                reject('图片加载失败');
            }
            img.src = src;
            document.body.createElement
        })

        return promise;
    }

    let src = "https://coding.imooc.com/static/module/class/content/img/255/section1-1.png";
    let result = loadImg(src);
    result.then(function(img){
        alert(`width: ${img.width}`)
        return img;
    }).then(function(img){
        alert(`height: ${img.height}`);
        return img;
    }).then(function(img){
        // 展示该图片
        document.body.appendChild(img);
    }).catch(function(ex){
        alert(ex)
    })
}